<?
session_start();
$lan = $_GET['l'];
if (!in_array($lan, array('en', 'cn')))
	$lan = 'cn';
$_SESSION['lang'] = $lan;
header('HTTP/1.1 301 Moved Permanently');
$ref = getenv('HTTP_REFERER');
$ctx = 'http://'.$_SERVER['HTTP_HOST'].'/';
if ($ref == '') {
	$ref = $lan;
} else if(stripos($ref, '.php') == false){
	$ref = str_replace('/en/', '/', $ref);
	if ($lan != 'cn') {
		$ref = str_replace($ctx, '/'.$lan.'/', $ref);
	}
}
header('Location: '.$ref);
exit();
?>